/**
 * 功能描述
 */

define(function (require, exports, module) {
	var Grid = require("grid");
	var Dialog = require("dialog");
	var queryChargeBackDataSvc = require("../store/queryChargeBackDataSvc");
	
    var instance = {
        initComponent: function (params,widget) {
        	var grid = new Grid({
        		parentNode : ".J-grid",
        		autoRender : false,
        		model: {
        			url : "api/planitemgroup/queryrefund",
        			params : function(){
    					var subnav = widget.get("subnav");
    					return {
                    			"servicePoint" : subnav.getValue("servicePoint"),
                    			"planItem.startDate" : subnav.getValue("startDate").start,
                    			"planItem.endDate" : subnav.getValue("startDate").end,
                    			"planItem.destination" : subnav.getValue("destination")
                    	};
    				},
    				columns: [{
    					 name : "destinationName",
    					 label : "目的地"
    				},{
    					 name : "startDate",
    					 label : "开始日期",
    					 format:"date",
    				},{
    					 name : "endDate",
    					 label : "结束日期",
    					 format:"date",
    				},{
    					 name : "adjustTypes.value",
    					 label : "调整类型"
    				},{
    					 name : "signUpNum",
    					 label : "报名人数",
    				},{
    					 name : "refundsNum",
    					 label : "应退费人数"
    				},{
    					 name : "alreadyRefundsNum",
    					 label : "已退费人数"
    				},{
    					 name : "show",
    					 label : "操作",
    					 format: "button",
    					 formatparams: [{
    						 id:"chargeback",
    						 text: "退费",
    						 handler: function(index,data,rowEle){
    							 if(data.refundsNum==data.alreadyRefundsNum){
    								 Dialog.alert({
    										content:"退费已完成",
    									});
    								 return;
    							 }
    							 var form = widget.get("form");
    							 widget.show([".J-form", ".J-editgrid"]).hide(".J-grid");
 								 widget.get("subnav").show(["save", "cancel"]).hide(["startDate", "destination", "servicePoint"]);
 								 form.setData(data); 
 								 form.setValue("destination",data.destinationName);
 								 form.setValue("startDate",data.startDate);
 								 form.setValue("endDate",data.endDate);
 								 form.setValue("signUpNum",data.signUpNum);
 								 queryChargeBackDataSvc.queryChargeBackData(data, widget);
    						 }
    					 },{
    						id:"detail",
 							text:"查看",
 							handler:function(index,data,rowEle){
 								var form = widget.get("form");
 								widget.show([".J-form", ".J-editgrid"]).hide(".J-grid");
 								form.setData(data);
 								form.setValue("destination",data.destinationName);
								form.setValue("startDate",data.startDate);
							    form.setValue("endDate",data.endDate);
								form.setValue("signUpNum",data.signUpNum);
 								widget.get("subnav").show(["cancel"]).hide(["save","startDate", "destination", "servicePoint"]);
 								queryChargeBackDataSvc.queryChargeBackData(data, widget);
 							} 
    					 }]
    				}]
        		}
        	});
        	 widget.set("grid", grid);
        }
    };
    module.exports = instance;
});
